package com.yang.controller;



import com.yang.domain.Result;
import com.yang.domain.entity.User;
import com.yang.enums.AppHttpCodeEnum;
import com.yang.exception.SystemException;
import com.yang.service.SystemLoginService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;


/**
 * <p>
 * 后台登录控制层
 * </p>
 * @author yang
 * @date 2023/5/29
 */
@RestController
public class LoginController {

    @Resource
    private SystemLoginService systemLoginService;

    @PostMapping("/user/login")
    public Result login(@RequestBody User user){

        if(!StringUtils.hasText(user.getUserName())){
            //提示 必须要传用户名
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return systemLoginService.login(user);
    }

    @PostMapping("/user/logout")
    public Result logout(){
        return systemLoginService.logout();
    }


    @GetMapping("getInfo")
    public Result getInfo(){
        return systemLoginService.getInfo();
    }


    @GetMapping("getRouters")
    public Result getRouters(){
        return systemLoginService.getRouters();
    }


}
